# !/usr/bin/python
# _*_ coding: utf-8 _*_
# @Time : 2021/5/25 10:38 上午
# @Author : liujun
# @File : sys.py
# @desc : 系统管理
from sqlalchemy import Column, VARCHAR, BIGINT, JSON, SMALLINT, DATETIME
from datetime import datetime

from db.base import Base


class SysUser(Base):
    """
    系统用户
    """
    id = Column(BIGINT, primary_key=True, index=True, comment='主键id')
    login_name = Column(VARCHAR(20), unique=True, index=True, nullable=True, comment='登录名')
    login_pwd = Column(VARCHAR(50), nullable=True, comment='登录密码')
    phone = Column(VARCHAR(16), unique=True, index=True, nullable=True, comment='手机号')
    email = Column(VARCHAR(128), unique=True, index=True, comment='邮箱')
    nick_name = Column(VARCHAR(20), comment='用户昵称')
    avatar = Column(JSON, comment='用户头像')
    sex = Column(SMALLINT, comment='性别：-1、未知。0、女。1、男。')
    state = Column(SMALLINT, nullable=True, comment='状态：0、禁用。1、启用。')
    create_time = Column(DATETIME, default=datetime.now, onupdate=datetime.now, comment='创建时间')
    update_time = Column(DATETIME, default=datetime.now, onupdate=datetime.now, comment='更新时间')


class SysUserRole(Base):
    """
    用户角色
    """
    id = Column(BIGINT, primary_key=True, index=True, comment='主键id')
    user_id = Column(BIGINT, nullable=True, comment='用户id')
    role_id = Column(BIGINT, nullable=True, comment='角色id')


class SysRole(Base):
    """
    系统角色
    """
    id = Column(BIGINT, primary_key=True, index=True, comment='主键id')
    role_name = Column(VARCHAR(20), unique=True, index=True, nullable=True, comment='角色名称')
    role_type = Column(SMALLINT, comment='角色类型：1、系统默认。2、自定义。')
    state = Column(SMALLINT, nullable=True, comment='状态：0、禁用。1、启用。')
    remark = Column(VARCHAR(255), comment='备注')
    create_time = Column(DATETIME, default=datetime.now, onupdate=datetime.now, comment='创建时间')
    update_time = Column(DATETIME, default=datetime.now, onupdate=datetime.now, comment='更新时间')


class SysRoleMenu(Base):
    """
    角色菜单
    """
    id = Column(BIGINT, primary_key=True, index=True, comment='主键id')
    role_id = Column(BIGINT, nullable=True, comment='角色id')
    menu_id = Column(BIGINT, nullable=True, comment='权限id')


class SysMenu(Base):
    """
    系统菜单
    """
    id = Column(BIGINT, primary_key=True, index=True, comment='主键id')
    title = Column(VARCHAR(20), nullable=True, comment='标题')
    pid = Column(BIGINT, nullable=True, comment='父id')
    menu_type = Column(SMALLINT, comment='类型：1、目录。2、菜单。3、按钮。')
    path = Column(VARCHAR(128), comment='路由')
    auth_code = Column(VARCHAR(30), comment='权限标识')
    icons = Column(VARCHAR(20), comment='图标')
    seq = Column(SMALLINT, index=True, nullable=True, comment='序号')
    is_hidden = Column(SMALLINT, nullable=True, comment='是否隐藏：1、是。0、否。')
    create_time = Column(DATETIME, default=datetime.now, onupdate=datetime.now, comment='创建时间')
    update_time = Column(DATETIME, default=datetime.now, onupdate=datetime.now, comment='更新时间')


class SysDict(Base):
    """
    数据字典
    """
    id = Column(BIGINT, primary_key=True, index=True, comment='主键id')
    dict_name = Column(VARCHAR(20), nullable=True, comment='字典名称')
    dict_code = Column(VARCHAR(30), nullable=True, comment='字典编号')
    seq = Column(SMALLINT, index=True, nullable=True, comment='序号')
    state = Column(SMALLINT, nullable=True, comment='状态：0、禁用。1、启用。')
    create_time = Column(DATETIME, default=datetime.now, onupdate=datetime.now, comment='创建时间')
    update_time = Column(DATETIME, default=datetime.now, onupdate=datetime.now, comment='更新时间')


class SysQuartz(Base):
    """
    定时任务
    """
    id = Column(BIGINT, primary_key=True, index=True, comment='主键id')
    groups = Column(VARCHAR(40), nullable=True, comment='任务分组')
    name = Column(VARCHAR(100), nullable=True, comment='任务名称（关键参数）')
    state = Column(SMALLINT, nullable=True, comment='状态：0、禁用。1、启用。')
    cron = Column(VARCHAR(30), comment='任务表达式')
    remark = Column(VARCHAR(255), comment='任务描述')
    create_time = Column(DATETIME, default=datetime.now, onupdate=datetime.now, comment='创建时间')
    update_time = Column(DATETIME, default=datetime.now, onupdate=datetime.now, comment='更新时间')


